
<template>
<div class="address">
  <Header><span slot="back" class="back" @click="goback" >返回</span>
    <span slot="home" class="home" @click="gohome">首页</span></Header>
    <van-address-edit
    :area-list="areaList"
    show-postal
   
    show-set-default
    show-search-result
    :search-result="searchResult"
    :area-columns-placeholder="['请选择', '请选择', '请选择']"
    @save="onSave"
    @delete="onDelete"
    @change-detail="onChangeDetail"
    @change-default="onChangeDefault"
    />
    <!-- <slot name="default" class="default-s">下部内容sss</slot> -->

    <!-- <div slot="default">下部内容</div> -->

</div>


</template>
<script>
import Header from "../../components/HeaderPublic";
import { Toast } from "vant";
import { areaList } from "@vant/area-data"; // 是级联数据
import {reqAddress} from "../../api/reqaddress";
export default {
data() {
return {
    areaList,
    searchResult: [],
    default_s:false,//改变选中状态（接口应该是有bug）
};
},
computed: {},
watch: {},
methods: {
    async onSave(content) {
      Toast('保存成功');
      /* this.$store.state.address.receiver = content.name;
      this.$store.state.address.regions = content.province + " " + content.city + " " + content.county;
      this.$store.state.address.address = content.addressDetail;
      this.$router.push("/cart"); */
      console.log(content);

      const result = await reqAddress({
        receiver:content.name,
        mobile:content.tel,
        regions:content.province + " " + content.city + " " + content.county,
        address:content.addressDetail,
        isDefault:content.isDefault
      });
      console.log(result);
      this.$router.push("/showaddress");

      // const result = await reqAddress({
      //   receiver:content.name,
      //   mobile:content.tel,
      //   regions:content.province + " " + content.city + " " + content.county,
      //   address:content.addressDetail,
      //   idDefault:this.default_s,
      // });
      // console.log(result);
      // this.$router.push("/showaddress");

    },
    onDelete() {
      Toast('delete');
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区',
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
    goback(){
        this.$router.back();
    },
    gohome(){
        this.$router.push("/home");
    },
    onChangeDefault(value){
      this.default_s=value;
    }
},
created() {},
mounted() {},
components: {
  Header,
},
};
</script>
<style scoped>
.default-s{
  width: 20px;
  height: 20px;
  background-color: chocolate;
}
</style>